import Vue from 'vue'
import {cloneDeep} from 'lodash'

export const GETACTIVITY = 'GETACTIVITY'
export const GETDATE = 'GETDATE'
export const GETCONTENT = 'GETCONTENT'
export const ADD_DATA = 'ADD_DATA'
export const REVISE_DATA = 'REVISE_DATA'
export const ENT_PARAM_DETETE = 'ENT_PARAM_DETETE'
export const ENT_PARAM_UPDATE_SORT = 'ENT_PARAM_UPDATE_SORT'
export const ENT_TAG_UPDATE_SEQ = 'ENT_TAG_UPDATE_SEQ'
export const DELETE_ACTIVITY_TYPE = 'DELETE_ACTIVITY_TYPE'
export const SET_EVALUATION_PERIOD = 'SET_EVALUATION_PERIOD'
export const CUSTOMER_TAG_ADD = 'CUSTOMER_TAG_ADD' // 新建客户标签
export const CUSTOMER_TAG_UPDATE = 'CUSTOMER_TAG_UPDATE' // 客户标签 更新
export const CUSTOMER_TAG_DELETE = 'CUSTOMER_TAG_DELETE' // 客户标签 删除
export const CUSTOMER_TAG_SORT = 'CUSTOMER_TAG_SORT' // 客户标签排序

const actions = {
  [GETACTIVITY] ({commit, dispatch}, data) {
    let _data = cloneDeep(data)
    return new Promise((resolve, reject) => {
      Vue.req.post('/http/saas/marketing/config/activityTypeList.json', _data, {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }
      }).then(res => {
        resolve(res)
      }).catch(err => {
      })
    })
  },
  [GETDATE] ({commit, dispatch}, data) {
    let _data = cloneDeep(data)
    return new Promise((resolve, reject) => {
      Vue.req.post('/http/saas/marketing/config/queryEvaluationPeriod.json', _data, {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }
      }).then(res => {
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  },
  [GETCONTENT] ({commit, dispatch}, data) {
    let _data = cloneDeep(data)
    return new Promise((resolve, reject) => {
      Vue.req.post('/http/saas/marketing/config/logList.json', _data, {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }
      }).then(res => {
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  },
  [ADD_DATA] ({commit, dispatch}, data) {
    let _data = cloneDeep(data)
    return new Promise((resolve, reject) => {
      Vue.req.post('/http/saas/entParam/add.json', _data, {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }
      }).then(res => {
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  },
  [REVISE_DATA] ({commit, dispatch}, data) {
    let _data = cloneDeep(data)
    return new Promise((resolve, reject) => {
      Vue.req.post('/http/saas/entParam/update.json', _data, {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }
      }).then(res => {
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  },
  [ENT_PARAM_DETETE] ({commit, dispatch}, data) {
    let _data = cloneDeep(data)
    return new Promise((resolve, reject) => {
      Vue.req.post('/http/saas/entParam/delete.json', _data, {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }
      }).then(res => {
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  },
  [ENT_PARAM_UPDATE_SORT] ({commit, dispatch}, data) {
    let _data = cloneDeep(data)
    return new Promise((resolve, reject) => {
      Vue.req.post('/http/saas/entParam/updateSeq.json', _data, {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }
      }).then(res => {
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  },
  [ENT_TAG_UPDATE_SEQ] ({commit, dispatch}, data) {
    let _data = cloneDeep(data)
    return new Promise((resolve, reject) => {
      Vue.req.post('/http/saas/empTag/updateSeq.json', _data, {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }
      }).then(res => {
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  },
  [DELETE_ACTIVITY_TYPE] ({commit, dispatch}, data) {
    let _data = cloneDeep(data)
    return new Promise((resolve, reject) => {
      Vue.req.post('/http/saas/marketing/config/deleteActivityType.json', _data, {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }
      }).then(res => {
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  },
  [SET_EVALUATION_PERIOD] ({commit, dispatch}, data) {
    let _data = cloneDeep(data)
    return new Promise((resolve, reject) => {
      Vue.req.post('/http/saas/marketing/config/setEvaluationPeriod.json', _data, {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }
      }).then(res => {
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  },
  [CUSTOMER_TAG_ADD] ({commit, dispatch}, data) {
    let _data = cloneDeep(data)
    return new Promise((resolve, reject) => {
      Vue.req.post('/http/saas/customerTag/add.json', _data, {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }
      }).then(res => {
        if (res.success) {
          commit('DELETE_CUSTOMER_TAG')
        }
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  },
  [CUSTOMER_TAG_UPDATE] ({commit, dispatch}, data) {
    let _data = cloneDeep(data)
    return new Promise((resolve, reject) => {
      Vue.req.post('/http/saas/customerTag/update.json', _data, {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }
      }).then(res => {
        if (res.success) {
          commit('DELETE_CUSTOMER_TAG')
        }
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  },
  [CUSTOMER_TAG_DELETE] ({commit, dispatch}, data) {
    let _data = cloneDeep(data)
    return new Promise((resolve, reject) => {
      Vue.req.post('/http/saas/customerTag/delete.json', _data, {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }
      }).then(res => {
        if (res.success) {
          commit('DELETE_CUSTOMER_TAG')
        }
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  },
  [CUSTOMER_TAG_SORT] ({commit, dispatch}, data) {
    let _data = cloneDeep(data)
    return new Promise((resolve, reject) => {
      Vue.req.post('/http/saas/customerTag/updateSeq.json', _data, {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }
      }).then(res => {
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  }
}

export default {
  actions
}
